<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">

</head>
<body>

<form class="layui-form" action="" id="modifyClazz">
    <div class="layui-form-item">
        <label class="layui-form-label">班级编号</label>
        <div class="layui-input-inline">
            <input type="text" name="clazzId" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">班级名称</label>
        <div class="layui-input-inline">
            <input type="text" name="clazzName" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">年级</label>
        <div class="layui-input-inline">
            <select name="clazzYear" lay-search="" id="clazzYear">
                <option value="2017">2017</option>
                <option value="2018">2018</option>
                <option value="2019">2019</option>
                <option value="2020">2020</option>
                <option value="2021">2021</option>
                <option value="2022">2022</option>
                <option value="2023">2023</option>
                <option value="2024">2024</option>

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">班主任</label>
        <div class="layui-input-inline">
            <select name="teacherId" lay-search="" id="teacherId">
            </select>
        </div>
    </div>
</form>

<script src="../../layuiadmin/layui/layui.js"></script>
<!--班主任option选项模板-->
<script id="optionTeacherId" type="text/html">
    {{#  layui.each(d.data, function(index, teacher){  }}
    <option value="{{teacher.teacherId}}">
        {{teacher.teacherId}}: {{teacher.teacherName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>
<script>
    layui.config({
        base: '../../layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['layer', 'form', 'laytpl', 'index'], function () {
        let layer = layui.layer,
            $ = layui.jquery,
            setter = layui.setter,
            laytpl = layui.laytpl,
            form = layui.form;

        /*
        * 加载年级信息
        * 加载教工号信息
        * */
        $(function () {
            $.ajax({
                url: setter.baseUrl + '/teacher/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionTeacherId.innerHTML
                            , view = document.getElementById('teacherId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
        });
        form.render();
    });

    //窗体传值
    function child(data) {
        layui.use(['layer', 'form'], function () {
            layui.jquery("input[name= 'clazzId']").val(data.clazzId);
            layui.jquery("input[name= 'clazzName']").val(data.clazzName);
            layui.jquery("#clazzYear").find("option[value="+data.clazzYear+"]").attr("selected",true);
            layui.jquery("#teacherId").find("option[value="+data.teacherId+"]").attr("selected",true);

        });
    }
</script>

</body>
</html>
